package com.liangzhong.model.match
{
	import flash.utils.ByteArray;

	/**
	 * 游戏过程描述
	 * @author lxh
	 * 
	 */	
	public class GameDes
	{
		/**
		 *比赛id 
		 */	
		public var matchId		:int;
		
		public var time :int;
		public var list :Array = [];
		//json 标志
		public var gameDes		:int = 1;
		
		public function GameDes()
		{
		}
		/**
		 * 
		 * @param data
		 * 
		 */		
		public function readData(data : ByteArray):void
		{
			matchId = data.readUnsignedInt();
			time = data.readShort();
			var playerStatus :PlayerStatus;
			var len :int = data.readShort();
			var i :int = 0;
			while(i < len)
			{
				playerStatus = new PlayerStatus();
				playerStatus.readData(data);
				if(playerStatus.playerIndex == 0)
				{
					list.unshift(playerStatus);
				}
				else
				{
					list.push(playerStatus);
				}
				i ++;
			}
		}
		public function toString():String
		{
			return "{time:" + time + ",matchId:" + matchId + ",list:" + list + "}"
		}
		/**
		 *解析记录中数据
		 * @param obj
		 */		
		public function parseHistoryData(obj :Object):void
		{
			for(var str:String in obj)
			{
				if(this.hasOwnProperty(str))
				{
					this[str] = obj[str];
				}
			}
			var tempList :Array = list;
			var playerStatus :PlayerStatus;
			list = [];
			for each(var lObj :Object in tempList)
			{
				playerStatus = new PlayerStatus();
				playerStatus.parseHistoryData(lObj);
				if(playerStatus.playerIndex == 0)
				{
					list.unshift(playerStatus);
				}
				else
				{
					list.push(playerStatus);
				}
			}
		}
	}
}